import { getPatientOrderHistory } from '@/services/patient/patientApi';
import { showMsg } from '@/utils/utils';
import ProTable, { ProColumns } from '@ant-design/pro-table';

const DetailOrderHistory = (props: DetailProps) => {

  const { patient_id, identity_no } = props;

  const columns: ProColumns[] = [
    {
      title: '订单号',
      dataIndex: 'order_id'
    },
    {
      title: '下单时间',
      dataIndex: 'create_time'
    },
    {
      title: '开单科室',
      dataIndex: 'create_dept_name'
    },
    {
      title: '商品所属科室',
      dataIndex: 'goods_dept_name'
    },
    {
      title: '结算金额',
      dataIndex: 'sett_price'
    },
    {
      title: '付款方式',
      dataIndex: 'pay_channel'
    },
    {
      title: '责任人',
      dataIndex: 'order_person'
    },
    {
      title: '开票状态',
      dataIndex: 'is_ballot',
      valueEnum: {
        Y: '是', N: '否'
      }
    },
    {
      title: '订单状态',
      dataIndex: 'order_status',
      valueEnum: {
        C: '开单状态', W: '待支付', P: '已支付', F: '已完成', E: '已作废', A: '退款待审批', R: '已退款', U: '退款处理中'
      }
    }
  ];

  return (
    <ProTable
      rowKey="order_id"
      style={{ marginTop: 12, padding: '0 12px' }}
      options={false}
      bordered
      search={false}
      columns={columns}
      params={{ patient_id, identity_no }}
      request={async (params) => {
        try {
          const res = await getPatientOrderHistory({ ...params });
          return { success: true, data: res.record_list, total: res.sum_record_num };
        } catch (reason: any) {
          showMsg(reason?.data?.errmsg);
          return { success: false, data: [] };
        }
      }}
      pagination={{ showQuickJumper: true }}
    />
  );
};

interface DetailProps {
  patient_id?: string;
  identity_no?: string;
}

export default DetailOrderHistory;
